unit Figures;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

const N = 800;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  Figure = class
    x, y : integer;
    procedure Draw; virtual; abstract;
  end;

  Square = class(Figure)
    a: integer;
    procedure Draw; override;
  end;
  FixedSquare = class(Square)
    constructor Create(num1,num2,num3: integer);
  end;
  RandomSquare = class(Square)
    constructor Create;
  end;
  Circle = class(Figure)
    R,c: integer;
    procedure Draw; override;
    constructor Create(num: integer);
  end;

var
  Form1: TForm1;
  mass : array [0..99] of Figure;
  i,num,num1,num2,num3: integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  for i:=0 to 99 do
    mass[i].Draw;
end;

{ FixedSquare }

constructor FixedSquare.Create;
begin
  x:=num1;
  y:=num2;
  a:=num3;
end;

{ Circle }

constructor Circle.Create(num: integer);
begin
  c:=num;
  x:=Random(Form1.Image1.Width);
  y:=Random(Form1.Image1.Height);
  R:=random(100);
end;

procedure Circle.Draw;
begin
  inherited;
  Form1.Image1.Canvas.Brush.Color:=c;
  Form1.Image1.Canvas.Ellipse(x, y, x+R, y+R);
  Form1.Image1.Canvas.Brush.Color:=clWhite;
end;

{ Square }

procedure Square.Draw;
begin
  inherited;
  Form1.Image1.Canvas.Rectangle(x,y,x+a,y+a);
end;

{ RandomSquare }

constructor RandomSquare.Create;
begin
  x:=Form1.Image1.Width;
  y:=Form1.Image1.Height;
  a:=random(100);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;
  for i:=0 to 24 do
  begin
    num1:=Random(Image1.Width);
    num2:=Random(Image1.Height);
    num3:=Random(100);
    mass[i]:=FixedSquare.Create(num1,num2,num3);
  end;
  for i:=25 to 49 do
    mass[i]:=RandomSquare.Create;
  for i:=50 to 99 do
  begin
    num:=Random(999999);
    mass[i]:=Circle.Create(num);
  end;
end;

end.
